package com.bwie.mq;

import com.bwie.mapper.SmsMapper;
import com.bwie.pojo.po.Sms;
import com.bwie.pojo.po.User;
import com.bwie.pojo.vo.MonthCarVo;
import com.bwie.utils.SendMsgUtil;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.amqp.utils.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

public class MessageConsumer implements MessageListener {
    @Autowired
    private SmsMapper smsMapper;

    /**
     * 月卡即将过期
     * @param message
     */
    @Override
    public void onMessage(Message message) {
        byte[] body = message.getBody();
        User user = (User) SerializationUtils.deserialize(body);


        String smsString="尊敬的"+user.getUsername()+"先生/女士，您的月卡即将过期请注意,谢谢";
        String isOk = SendMsgUtil.sendSms(user.getUserPhone(), "11111");

        //解析发送结果，保存到消息发送记录表中。
        Sms sms = new Sms();
        sms.setSmsRemarks(smsString);
        sms.setSmsTime(new Date());
        sms.setSmsPhone(user.getUserPhone());
        sms.setSmsResp(isOk);

        smsMapper.addSms1(sms);
    }
}
